<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客列表</title>
    <link rel="stylesheet" href="css/conmmon.css">
    <link rel="stylesheet" href="css/blog_list.css">
    <script src="js/jquery.min.js"></script>
</head>

<body>
    <!-- 导航栏 -->
    <div class="nav">
        <img src="img/touxaing.jpg" alt="">
        <span class="title">我的博客系统</span>
        <!-- 用来占据中间位置 -->
        <span class="spacer"></span>
        <a href="index.html">主页</a>
        <a href="blog_edit.html">写博客</a>
        <a href="login.html">登陆</a>
        <!-- <a href="#">注销</a> -->
    </div>
    <!-- 版心 -->
    <div class="container">
        <!-- 左侧个人信息 -->
        <div class="container-left">
        </div>
        
        <!-- 右侧内容详情 -->
        <div class="container-right">
            <div id="alist">
            </div>
            <div id="pageDiv" style="text-align:center;padding-top:30px;padding-bottom:30px;">
                <a href="javascript:lastPage();">上一页</a>
                <a href="javascript:nextPage();">下一页</a>
            </div>
        </div>
    </div>
    <script>
        //公共的获取URL中某个参数的方法
        function getURLParam(key){
            var params=location.search;
            if(params.indexOf("?")>=0){
                params=params.substring(1);
                var paramArr=params.split('&');
                for(var i=0; i<paramArr.length;i++){
                    var namevalues=paramArr[i].split('=');
                    if(namevalues[0]==key){
                        return namevalues[1];
                    }
                }
            }else{
                return "";
            }
        } 
        var currPage=getURLParam("cp")==""?1:getURLParam("cp");//当前的页面
        var pagesize=getURLParam("ps")==""?2:getURLParam("ps");//每页显示最大条数

        //上一页
        function lastPage(){
            if(currPage>1){
                currPage--;
            }else{
                //当前已经在首页
                alert("当前已经在首页了！");
                return;
            }
            location.href="blog_list.html?cp="+currPage+"&ps="+pagesize;
        }
        //下一页
        function nextPage(){
            currPage++;
            location.href="blog_list.html?cp="+currPage+"&ps="+pagesize;
        }
        //将请求发送给后端 请求后端查询列表
        function loadArtList(){
            jQuery.ajax({
                url:"artlist",
                type:"GET",
                data:{"cp":currPage,"ps":pagesize},
                success:function(result){
                    if(result!=null &&result.succ==200 && result.data!=null && result.data.uid>0){

                    }else{
                        jQuery("#alist").html("<h2>暂无文章</h2>");
                        jQuery("#pageDiv").hide();
                    }
                }
            });
        }
        loadArtList();
    </script>
</body>

</html>